/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package daa3.pkg2013;

/**
 * @author 
 * Sergio Gonzalez Piedra
 * Victor Borja Guimera 
 * Jairo Cerezo Díaz-Cardiel
 */
public class GenerarCodigo {
    private Caracter nodoRaiz;
    private char c;
    private char array[];
    private int i;
    private String bitPattern="";

    public String getBitPattern() {
        return bitPattern;
    }

    public void setBitPattern(String bitPattern) {
        this.bitPattern = bitPattern;
    }

    public GenerarCodigo(Caracter nodo, char []array) {
        String aux;
        int i;
        nodoRaiz=nodo;
        this.array = array;
        for(i=0 ;i<array.length;i++){
            aux=busqueda(nodoRaiz,"",array[i]);
            bitPattern += aux +" ";
                      
        }
    }
    public String busqueda(Caracter nodoRaiz,String valor, char c){
        String aux="";
        if (nodoRaiz != null){
            if(nodoRaiz.getIzq()!=null){
                aux=busqueda(nodoRaiz.getIzq(), valor+"0", c);
            }
            if(nodoRaiz.getCaracter()== c){
                return valor;
            }
            else{
                if(aux == ""){
                    return busqueda(nodoRaiz.getDer(),valor+"1",c);
                }
                else{
                    return aux;
                }
            }                
        }
        else{
            return "";
        }
    }
    
    
    
}
